<template>
  <div>
    <peader :title="'购物车'" :bgColor="'pink'" />
    <div class="list" style="padding: 45px 0 50px">
      <goos v-for="obj in list" :key="obj.id" :goodsObj="obj" />
    </div>
    <foater
      @quanxuan="quanxuan"
      :xiaoxuan1="xiaoxuan"
      :jiesuan="jiesuan"
      :zongjia="zongjia"
    />
  </div>
</template>

<script>
import peader from "./comintig/Myheader/index.vue";
import goos from "./comintig/MyGoos/index.vue";
import foater from "./comintig/MyFooter/index.vue";
export default {
  data() {
    return {
      list: [],
    };
  },
  components: {
    peader,
    goos,
    foater,
  },
  async created() {
    const resp = await this.$https({
      method: "GET",
      url: "/api/cart",
    });
    this.list = resp.data.list;
  },
  computed: {
    xiaoxuan() {
      return this.list.every((item) => item.goods_state === true);
    },
    jiesuan() {
      return this.list.reduce((sum, obj) => {
        if (obj.goods_state) {
          sum += obj.goods_count;
        }
        return sum;
      }, 0);
    },
    zongjia() {
      return this.list.reduce((sum, obj) => {
        if (obj.goods_state) {
          sum += obj.goods_price * obj.goods_count;
        }
        return sum 
      },0);
    },
  },
  methods: {
    quanxuan(e) {
      this.list.forEach((item) => (item.goods_state = e));
    },
  },
};
</script>

<style>
</style>